package com.ytd.smartcanteen.weighting.dao;

import androidx.room.Dao;
import androidx.room.Delete;
import androidx.room.Insert;
import androidx.room.OnConflictStrategy;
import androidx.room.Query;
import androidx.room.Update;

import com.ytd.smartcanteen.weighting.bean.MealInfo;

import java.util.List;

/**
 * 餐品表
 *
 * @author gaoguanchao
 * @since 2023/3/24
 */
@Dao
public interface MealInfoDao {

    @Insert(onConflict = OnConflictStrategy.REPLACE)
    void insert(MealInfo mealInfo);

    @Update
    void update(MealInfo mealInfo);

    @Delete
    void delete(MealInfo mealInfo);

    @Query("DELETE FROM mealinfo")
    void deleteAll();

    @Query("SELECT * FROM mealinfo")
    List<MealInfo> getAll();

    @Query("SELECT * FROM mealinfo WHERE foodId =:foodId")
    MealInfo getMealForId(String foodId);

    @Query("SELECT foodCategoryId FROM mealinfo WHERE foodId =:foodId")
    String getMealCategoryId(String foodId);

    @Query("SELECT * FROM mealinfo where foodCategoryId = :category")
    List<MealInfo> getMealForCategory(String category);

    @Query("SELECT * FROM mealinfo where foodCategoryId = :categoryId and foodName like :text")
    List<MealInfo> getMealForCategoryLikeName(String categoryId, String text);

    @Query("SELECT * FROM mealinfo where foodName like :text")
    List<MealInfo> getMealLikeName(String text);

    @Query("update mealinfo set foodCategoryName = :categoryName where foodCategoryId = :id")
    void updateCategoryInfo(String id, String categoryName);
}
